#include <bits/stdc++.h>
using namespace std;

using ll = int64_t;
const int N = 20;
int t;
int a[N];

int main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    cin >> t;
    while(t--){
        int x, n; cin >> x >> n;
        int sum = 0;
        if(n % 2 == 0) sum = 0;
        else if(n % 2 == 1) sum = x;
        cout << sum << '\n';
    }
    return 0;
}